<?php
define('ABSPATH', dirname(__FILE__) . '/');
if (function_exists('xdebug_start_trace')) {
    //xdebug_start_trace(ABSPATH . 'trace.xt' . uniqid());
}
ob_implicit_flush(true);
require_once(dirname(__FILE__) . '/../include.all.php');

$retried_summary = createRetryFunction(function($a, $b) {
    $result = new Deferred();
    setTimeout(function() use($a, $b, &$result) {
        $rand = rand(1,3);
        echo "try($rand)\n";
        if($rand == 1) {
            $result->callback($a + $b);
        } else {
            $result->errback(NULL);
        }
    }, 1);
    return $result;
}, 5);
$def = $retried_summary(2, 5);
$def->addCallback(function ($result) {
    echo "result: $result\n";
});

Tick::getInstance()->startExecution();
//$_def->callback('result2');
